#ifndef __MEDIATOR_H__
#define __MEDIATOR_H__

#include <iostream>

class Country;
/// @brief 联合国基类（抽象中介类）
class United
{
public:
    virtual void Publish(const std::string &message, Country *pCountry) = 0;
};

/// @brief 国家基类（抽象同事类）
class Country
{
protected:
    United *m_pMediator{};
    std::string m_name{};

public:
    Country(United *pMediator)
        : m_pMediator(pMediator) {}
    void SetMediator(United *pMediator)
    {
        m_pMediator = pMediator;
    }
    /// @brief 发布消息
    /// @param message 消息内容
    virtual void Publish(const std::string &message) = 0;
    /// @brief 接收消息
    /// @param message 消息内容
    virtual void Receive(const std::string &message) = 0;
};
/// @brief 美国
class USA : public Country
{
public:
    USA(United *pMediator)
        : Country(pMediator)
    {
        m_name = "美国";
    }
    virtual void Publish(const std::string &message) override
    {
        m_pMediator->Publish(message, this);
    }
    virtual void Receive(const std::string &message) override
    {
        printf("%s接收到：%s\n", m_name.c_str(), message.c_str());
    }
};
/// @brief 伊朗
class Iran : public Country
{
public:
    Iran(United *pMediator)
        : Country(pMediator)
    {
        m_name = "伊朗";
    }
    virtual void Publish(const std::string &message) override
    {
        m_pMediator->Publish(message, this);
    }
    virtual void Receive(const std::string &message) override
    {
        printf("%s接收到：%s\n", m_name.c_str(), message.c_str());
    }
};
/// @brief 安理会
class SecurityCouncil : public United
{
protected:
    USA *m_pUSA{};
    Iran *m_pIran{};

public:
    void SetUSA(USA *pUSA)
    {
        m_pUSA = pUSA;
    }
    void SetIran(Iran *pIran)
    {
        m_pIran = pIran;
    }
    virtual void Publish(const std::string &message, Country *pCountry) override
    {
        if (pCountry == m_pUSA)
            m_pIran->Receive(message);
        else
            m_pUSA->Receive(message);
    }
};

#endif